-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic support for Jest runner #335
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
"test:e2e:build": "detox build" | ||
} | ||
``` | ||
|
||
We need the `--runInBand` as detox doesn't support parallelism yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will running without the flag run tests serially?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the flag here so if you use detox test -r jest
it is always there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is stopping detox from parallelism?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few things, mainly controlling multiple simulators. It's in our roadmap, shouldn't be too hard.
detox/local-cli/detox-test.js
Outdated
@@ -38,6 +38,9 @@ switch (program.runner) { | |||
case 'mocha': | |||
command = `node_modules/.bin/${program.runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig} ${configuration} ${loglevel} ${cleanup} ${reuse} ${debugSynchronization} ${artifactsLocation}`; | |||
break; | |||
case 'jest': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about passing detox command line args? Will those work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can think of a way doing this. Although, in this version I wasn't aiming to provide this. If this is mandatory, we can discuss the approach
Sorry, misread your comment. What do you mean by "detox cli args"? Can you make an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is, the feature is not 100% usable without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
detox test --configuration ios.sim.release
detox test --loglevel verbose
detox test --debug-synchronization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which flags are important?
In the previous version there were no recommendations regarding flags so kept it out of scope. However, I'm fine adding important flags to make jest support even better 💪 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rotemmiz what is the goal?
- tests can access CLI arguments
or - detox can access CLI arguments
If we talk about the second one, then it already works like this (commander parses arguments before passing them to test runner)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, but we execute a child process and these argument are not being passed into it.
cp.execSync(command, {stdio: 'inherit'});
We probably just need to pass them on...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, now I see. Indeed, we just need to pass arguments to the child process. Then there will be no point in passing all these flags in the command itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like jest
doesn't support allow custom CLI parameters. The only approach I see is to use environment vars.
Using ENV vars will imply changes on the mocha part and the way test cases gets parameters overall.
UPD: I can update argparse
library and CLI so instead of additional flags it'll create one-time ENV variables. For user it'll be still the same, all mapping will happen under the hood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea @Kureev, thank you so much for your efforts here 👍
@rotemmiz just a question, would you add different runner to the test matrix? |
Totally tangential question, but here goes... Been playing around with detox and jest, and I noticed that if I have two test files (e.g. Edit: Happy to create a separate issue if you want. |
@hellogerard I believe it is related to |
I didn't use Detox with Jest yet, but from what I could see, there is no way to run a global |
@DanielMSchmidt Not sure, the only thing we need to test here are is how the test runner is triggered, so it's pretty easy to test with unit tests. |
@rotemmiz Thanks for that link. There's a PR that closes that issue. Once it's merged, it looks like it can solve the global setup issue. PR is jestjs/jest#4506 |
Quick update on the PR: we discussed the way to go with @rotemmiz so you may expect that I'll push my changes today-tomorrow 😉 |
Hmm. I may have spoke too soon, or I don't understand the jest changes. I tried to use the new global setup by doing the following:
But no dice. Not only is it running EDIT: Forgot to mention I did in fact install |
Hi @rotemmiz! It seems like I have all my unit tests passing locally, but got some issues on CI 🤔 . Can you help me to figure why? |
Seems like some of the params passed to mocha have changed, try running |
@rotemmiz seems that after the last fix CI dies due to timeout 😐 . Should I increase it a little bit? |
I have a feeling that something has changed in Travis. We’ll need to debug it, and add better visibility to the build log. Does everything work locally? |
I have the same problem with timeout on the local machine, but I'll try to extend it (locally) and let you know if it actually works. |
Ok, it gets stuck at
Even if I run my emulator manually, still the same issue... No idea how to debug it. Any suggestions? UPD: Got an error after timeout
Not sure if it is anyhow related to my patch though 🤔 |
I’m not near a computer to verify that, but I think that —args is misplaced (check the last command vs Detox 5.8.2) |
I found an issue in my local setup: seems for some reason my emulator that was used by tests got stuck (no idea, really). After resetting all the settings, everything worked. Will report once I finish all tests locally. 🤞 |
I can confirm that all tests (including e2e) are green. cc @rotemmiz |
Rerunning your build |
I want to add a very important request to this feature: since users choose and setup their test runner probably stick with it for more than an hour, it is important to add an option to configure the test runner in the detox config inside This should be a very small addition. |
If there is a way to reload your iOS emulator on Travis, I would do that first. For me it solved exactly the same problem on my local machine. |
Ready for review, @rotemmiz |
@Kureev, some of our users use Detox with mocha (or any other test runner for that matter) independently of detox-cli. The current change breaks their setup since they can not pass arguments anymore. |
Not sure I follow. All arguments are respected 🤔 |
Detox core now only supports env vars, not argv. Try running |
Sure, but this is not about Detox either. Detox should be run only by detox-cli and |
I don't agree, Detox is test runner independent, and we want to keep it that way. In any case, using argv (where possible) is a better and responsible solution, it removes any possibility of environment var leaks. |
I expect it to be not supported (yet). Otherwise I would expect an article in docs and/or other guidelines' describing how to setup Detox with your-faviourite-tool.
I'm fine changing code to support |
Should be good now. First we look for the flag in |
@@ -975,7 +975,7 @@ | |||
buildSettings = { | |||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | |||
DEAD_CODE_STRIPPING = NO; | |||
DEVELOPMENT_TEAM = ""; | |||
DEVELOPMENT_TEAM = J966JLDEF9; | |||
INFOPLIST_FILE = example/Info.plist; | |||
IPHONEOS_DEPLOYMENT_TARGET = 9.0; | |||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was that added in purpose?
I reset |
The last CI run was flaky 😒 I changed nothing (okok, I removed my cert pub hash from |
detox/local-cli/detox-test.js
Outdated
loglevel: program.loglevel, | ||
cleanup: program.cleanup, | ||
reuse: program.reuse, | ||
debugSynchronization: program.debugSynchronization ? 3000 : '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kureev , wouldn't this override every number value with 3000 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rotemmiz! Nice catch, fixed! 😉
🎉 !!! |
@hellogerard Jest's TestEnvironment is sandboxed (see this) |
With this PR merged in, users will be capable of using Jest test runner without significant problems:
detox test -r jest